package com.example.system.security.mapper;

import com.example.common.entity.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigInteger;
import java.util.List;

@Mapper
public interface UserMapper {
    
    /**
     * 根据用户名查询用户信息
     * @param username 用户名
     * @return SysUser实体，找不到返回null
     */
    @Select("SELECT id, username, password, enabled FROM sys_user WHERE username = #{username} " +
                "LIMIT 1")
    SysUser selectByUsername(@Param("username") String username);
    
    /**
     * 根据用户ID查询权限列表
     * @param userId 用户ID
     * @return 权限字符串列表
     */
    @Select("""
        SELECT DISTINCT m.permission
        FROM sys_menu m
        JOIN sys_roles_menus rm ON m.menu_id = rm.menu_id
        JOIN sys_user_roles ur ON rm.role_id = ur.role_id
        WHERE ur.user_id = #{userId}
          AND m.permission IS NOT NULL
    """)
    List<String> selectPermissionsByUserId(@Param("userId") BigInteger userId);
    
    
}
